<link rel="stylesheet" href="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.css">
<script src="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.js"></script>
<script src="<%- Virtual_Path.Static %>jquery.plugin/birthday/birthday.js"></script>
<div class="anchor-tab">
    <ul class="tab">
        <li><a href="/member/family/income">公会收入</a></li>
        <li><a href="/member/family/anchor">公会艺人</a></li>
        <!--<li  class="on"><a href="/member/family/anchor_income">艺人收入</a></li>-->
        <!--<li><a href="/member/family/anchor_salary">基本工资</a></li>-->
        <li><a href="/member/family/anchor_live">直播数据</a></li>
    </ul>
</div>
<div class="anchor-cont">
    <div class="tabs-cont">
        <div class="hander-func">
            <p class="fl">查询时间：
                <select name="Birthday_Year" id="sel_year" rel=""></select>
                年
                <select name="Birthday_Month" id="sel_month" rel=""></select>
                月
            </p>
            <p class="fl">
                用户ID：
                <input type="text" class="qing-input" placeholder="" id="userIds" name="user_ID">
            </p>
            <p class="fl">
                艺人名称：
                <input type="text" class="qing-input" placeholder="" id="nicknames" name="NickName">
            </p>
            <a id="find_family_anchor" class="c-button fl" href="javascript:;">查询</a>
        </div>

        <div class="tableinfo">
            <table class="tabinfo">
                <thead>
                <tr>
                    <th>日期</th>
                    <th>艺人名称</th>
                    <th>艺人Id</th>
                    <th>金额（元）</th>
                    <th>状态</th>
                </tr>
                </thead>
                <tbody id="J_OrderList">
                <tr>
                    <td colspan="5">加载中...</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div id="AjaxPagination" class="pagination"></div>
    </div>
</div>
<script>
    $(function(){
        var Create_Date='';
        var User_ID='';
        var NickName='';
        //时间搜索插件
        $.ms_DatePicker({
            YearSelector: ".sel_year",
            MonthSelector: ".sel_month",
        });
        $.ms_DatePicker();

        var _ThisPage = {
            PageParm: {
                P_Get: true,
                Loading: false, //加载中
                Total: null,       //总条数
                MaxCode: "",    //MaxCode
                Start: 0,       //开始
                Length: 3      //页长度
            }
        };

        //搜索
        $('#find_family_anchor').on('click',function () {
            var param={};
            _ThisPage = {
                PageParm: {
                    P_Get: true,
                    Loading: false, //加载中
                    Total: null,       //总条数
                    MaxCode: "",    //MaxCode
                    Start: 0,       //开始
                    Length: 3      //页长度
                }
            };
            param.year=$.trim($('#sel_year').val());
            param.month=$.trim($('#sel_month').val());
            param.User_ID=$.trim($('#userids').val());
            param.NickName=$.trim($('#nicknames').val());

            if(param.month){
                if(param.year==0){
                    $.KOC.Tips.Open("Error", '请选择年份！', {Timeout: 2000});
                    return;
                }
            }
            Create_Date=param.year+'-'+param.month;
            if(param.User_ID){
                User_ID=param.User_ID;
            }
            if(param.NickName){
                NickName=param.NickName;
            }
            AnchorLive();
        });
        if(Create_Date==''){
            AnchorLive();
        }
        function AnchorLive(){
            $.ajax({
                url: '/ajax/user.order-live.pagefamily',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col:"Create_Date",
                    Sort_Dir: "DESC",
                    Create_Date:Create_Date,
                    User_ID:User_ID,
                    NickName:NickName
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    if(data.iTotalRecords>0){
                        $("#AjaxPagination").empty().pagination(data.iTotalRecords, {
                            num_edge_entries: 2, //边缘页数
                            num_display_entries: 5, //主体页数
                            callback: PageCallback,
                            items_per_page: _ThisPage.PageParm.Length, //每页显示1项
                            prev_text: "前一页",
                            next_text: "后一页"
                        });
                    }else{
                        var _html = RenderPage(null,data.iTotalRecords);
                        $("#AjaxPagination").empty();
                        $('#J_OrderList').empty().html(_html);
                    }
                }
            });
        }

        function PageCallback(id) {
            _ThisPage.PageParm.Start =id * _ThisPage.PageParm.Length;
            InitTable(id);
        }

        function  InitTable(index) {
            $.ajax({
                url: '/ajax/user.order-live.pagefamily',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col:"Create_Date",
                    Sort_Dir: "DESC",
                    Create_Date:Create_Date,
                    User_ID:User_ID,
                    NickName:NickName
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    _ThisPage.PageParm.MaxCode = data.sMaxCode;
                    _ThisPage.PageParm.Start += _ThisPage.PageParm.Length;
                    var _html = '';
                    if(_ThisPage.PageParm.Total>0){
                        _.forEach(data.aaData, function (ThisValue) {
                            _html += RenderPage(ThisValue);
                        });
                    }
                    $('#J_OrderList').empty().html(_html);
                }
            });
        }
        function  RenderPage(ThisValue,len) {
            var _html = '';
            if(len <= 0){
                _html +='<tr>' +
                        '<td colspan="5">'+'没有数据！'+
                        '</td>'+
                        '</tr>';
            }else{
                _html +='<tr>' +
                        '<td>'+moment(ThisValue.Create_Date).format('YYYY-MM-DD HH:mm:ss')+
                        '</td>'+
                        '<td>'+ThisValue.User_ID+
                        '</td>'+
                        '<td>'+ThisValue.User_NickName+
                        '</td>'+
                        '<td>'+parseInt(ThisValue.Duration/1440)+
                        '</td>'+
                        '<td>'+ ThisValue.Duration+
                        '</td>'+
                        '<td>'+ ThisValue.Gift_Coin_Anchor+
                        '</td>'+
                        '<td><a href="/member/family/anchor_live/detail/'+ThisValue.User_ID+'">明细</a>' +
                        '</td>'+
                        '</tr>';
            }
            return _html;
        }
    });
</script>